"""
定制pytest-html的各项内容:
"""

import pytest
from datetime import datetime
from py.xml import html


# 编辑报告标题
def pytest_html_report_title(report):
    report.title = "pytest-html 插件生成 html 格式的测试报告"


# 运行测试前修改环境信息
def pytest_configure(config):
    config._metadata['start_time'] = datetime.utcnow()


# 运行测试后修改环境信息
@pytest.hookimpl(tryfirst=True)
def pytest_sessionfinish(session, exitstatus):
    session.config._metadata['end_time'] = datetime.utcnow()


# 编辑摘要信息
def pytest_html_results_summary(prefix, summary, postfix):
    prefix.extend([html.p("Summary:summary")])


# 新增表头:Time
def pytest_html_results_table_header(cells):
    cells.insert(1, html.th("Time", class_="sortable time", col="time"))
    cells.pop()


# 新增dt:时间
def pytest_html_results_table_row(report, cells):
    cells.insert(1, html.td(datetime.utcnow(), class_="col-time"))
    cells.pop()
